<?php


namespace App\Common\Http;


class ResponseMsg
{
    /**
     * @Message("Server Error！")
     */


    const SUCCESS = 200; //成功

    const CREATED = 201;   //已受理,无返回

    const ACCEPTED = 202;   //任务处理

    const CLIENT_ERROR = 400; //客户端错误


    const Unauthorized = 401;

    const Forbidden = 403;

    const Not_Found = 404;

    const SERVICE_ERROR = 500; //服务端错误

    const Gateway_Timeout = 504;


    /**
     * @param $msg
     * @param array $data
     * @return array
     */
    public static function success($msg, $data = [])
    {
        return self::msg($msg, self::SUCCESS, $data);

    }



    /**
     * @param $msg
     * @param array $data
     * @return array
     */
    public static function servieError($msg, $data = [])
    {
        return self::msg($msg, self::SERVICE_ERROR, $data);

    }


    /**
     * @param $msg
     * @param array $data
     * @return array
     */
    public static function clinetError($msg, $data = [])
    {
        return self::msg($msg, self::CLIENT_ERROR, $data);

    }


    /**
     * @param $msg
     * @param $code
     * @param array $data
     */
    public static function msg(string $msg, int $code, $data = [])
    {
        return [
            'msg' => $msg,
            'code' => $code,
            'data' => $data
        ];
    }

    /**
     * page
     * @param array $list
     * @param int $page
     * @param $page_size
     * @param $totals
     * @return array
     * date:2021/9/7
     * time:17:30
     * auth：xyc
     */
    public static function page(array $list, int $totals, int $page = 1, int $page_size = 10)
    {
        return [
            'page' => $page,
            'page_size' => $page_size,
            'totals' => $totals,
            'total_pages' => ceil($totals / $page_size),
            'list' => $list
        ];
    }
}